// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

import {utils} from "../utils/utils";
import {getItem, getItemName, getReward, ResType} from "../config/config";

const {ccclass, property} = cc._decorator;

@ccclass
export default class ItemFrame extends cc.Component {

  @property(cc.Label)
  labelName: cc.Label = null;

  @property(cc.Label)
  labelNum: cc.Label = null;

  @property(cc.Sprite)
  iconSprite: cc.Sprite = null;

  // onLoad () {}

  start() {
    // utils.setIcon(this.iconSprite, )
  }

  setItemData(itemId: number, num: number = 1, itemType: ResType = ResType.skin) {
    this.iconSprite.node.active = false;
    const iconId = getItem(itemId, 'iconid');
    utils.setIcon(this.iconSprite, iconId, itemType)
    this.labelNum.string = num.toString()
    this.labelName.string = getItemName(itemId)
  }

  setRewardId(rewardId: number) {
    const rewardConfig = getReward(rewardId)
    this.setItemData(rewardConfig.itemid, rewardConfig.number, rewardConfig.type)
  }
}
